package com.xuetang9.fujian.threaddemo;

/**
 * @author: fujian
 * @description: 主线程
 * @date: 2021/5/2 10:11
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo
 **/
@SuppressWarnings("all")
public class MyThread {
    static class TreadDemo extends Thread{
        private int num;

        public TreadDemo(int num) {
            this.num = num;
            this.setName("报数线程");
        }

        @Override
        public void run() {
            // 在线程中必须实现run方法，线程开启时会自动调用run方法，不需要程序员手动调用
            while (--num >= 0){
                System.out.println("当前num = " + num);
            }
            System.out.println("线程：" + Thread.currentThread().getName() + "执行结束");
        }
    }
    public static void main(String[] args) {
//        Thread.currentThread()
//        返回当前调用这个方法的线程
//        System.out.println(Thread.currentThread().getName());
        MyThread.TreadDemo threadDemo = new TreadDemo(20);
        threadDemo.start();
    }

}

